﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework.Constraints;

namespace TimScripts.BF4Rcon.Test
{
    public class PlayerInfoBlockPlayerCollectionTests
    {
        PlayerInfoBlockCreator Data;

        [SetUp]
        public void SetUp()
        {
            Data = new PlayerInfoBlockCreator();
        }

        [Test]
        public void DataIsParsedWithoutOffset()
        {
            List<string> data;
            PlayerInfoBlockPlayerCollection players;
            string playerName = "foo";

            data = Data.AddProperties("name", "awesomeness").AddPlayers(playerName).CreatePlayerInfoBlock();

            players = new PlayerInfoBlockPlayerCollection(data);

            Assert.AreEqual(1, players.Count);
            Assert.AreEqual(playerName, players[0].Name);
            Assert.AreEqual(string.Empty, players[0]["awesomeness"]);
        }

        [Test]
        public void DataIsParsedWithOffset()
        {
            List<string> data;
            PlayerInfoBlockPlayerCollection players;
            string playerName = "foo";

            data = Data.AddProperties("name", "awesomeness").AddPlayers(playerName).CreatePlayerInfoBlock("OK");

            players = new PlayerInfoBlockPlayerCollection(data, 1);

            Assert.AreEqual(1, players.Count);
            Assert.AreEqual(playerName, players[0].Name);
            Assert.AreEqual(string.Empty, players[0]["awesomeness"]);
        }

        [Test]
        public void EnumeratorWorks()
        {
            List<string> data;
            PlayerInfoBlockPlayerCollection players;
            string[] playerNames = { "foo", "bar", "baz" };

            data = Data.AddProperties("name", "awesomeness").AddPlayers(playerNames).CreatePlayerInfoBlock("OK");

            players = new PlayerInfoBlockPlayerCollection(data, 1);

            foreach (Player p in players)
            {
                Assert.That(playerNames, Contains.Item(p.Name));
                Assert.AreEqual(string.Empty, p["awesomeness"]);
            }
        }

    }
}
